<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000,initial-scale=1.0,maximum-scale=1.0">
		<link href="Public/Admin/css/style.css" type="text/css" rel="stylesheet"  />
		<link href="Public/Admin/css/skin/fonts/font-awesome.min.css" type="text/css" rel="stylesheet"/>
		<script type="text/javascript" src="Public/Admin/js/jquery-1.8.2.min.js"></script>
		<script type="text/javascript" src="Public/Admin/js/effect.js"></script>
		<script type="text/javascript" src="Public/Admin/js/common.js"></script>
	    <!--载入百度编辑器-->
	    <script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
    	<!--uploadify-->
    	<script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
    	<link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
    	<!--异步-->
		<script type="text/javascript" charset="utf-8">
	    	$(function(){
	    		$("[name=category_cid]").change(function(){
	    			//抓取元素
					var type_tid = $('option:selected').attr('type_tid');
					//给隐藏域赋值
					//$('[name=form_fid]').val(fid);
					//发送异步
					$.ajax({
						type:"post",
						url:"{{U('Goods/ajaxTypeAttr')}}",
						data:{id:type_tid},
						dataType:'json',
						success:function(phpData){//请求之后，响应成功执行
							//属性（不可选）
							var Attr = '';
							//规格（可选）
							var Spec = '';
							//document.write(phpData);
							$.each(phpData,function(k,v){
								if(v.class==0){//属性
									Attr += '<tr class="info">'+
											'<td class="w160" align="center">'+ v.taname +'</td>'+
											'<td>'+
											'<select name="arr['+v.taid+']"><option value="">请选择</option>';
									$.each(v.tavalue,function(kk,vv){
										Attr += '<option value="'+ vv +'">'+ vv +'</option>';	
									});
									Attr += '</select></td></tr>';
									//document.write(Attr);
								}
								else{//规格
									Spec += '<tr class="info">'+
											'<td class="w160" align="center">'+ v.taname +'</td>'+
											'<td>'+
											'<select name="spec['+v.taid+'][value][]"><option value="">请选择</option>';
									$.each(v.tavalue,function(kk,vv){
										Spec += '<option value="'+ vv +'">'+ vv +'</option>';	
									});
									Spec += '</select></td>';
									Spec += '<td>附加价格：<input type="text" name="spec['+v.taid+'][add_price][]" /></td>';
									Spec += '<td><span class="btn-gray add-spec">增加规格</span></td>';
									Spec += '</tr>';
									//document.write(Spec);
								}
							});
						    //插入属性
		    				$('#attr').html(Attr);
		    				$('#spec').html(Spec);
						}
					});				     
	    		})	    		
	    		//添加规格
	   			$(".add-spec").live('click',function(){
					var parentTr = $(this).parents('.info');
					//克隆
					var cloneTr = parentTr.clone();
					cloneTr.find('.add-spec').removeClass('add-spec').addClass('remove-spec').html('删除规格');
					//插入到下一行
					parentTr.after(cloneTr);
					
	    		})
	    		//删除规格
	    		$(".remove-spec").live('click',function(){
	    			$(this).parents('tr').remove();
	    		})	
	    	})
	    </script>
		<!--异步_ok-->  	
    	<style type="text/css">
    		.close_img,.close_img2{font-family: "微软雅黑";padding:2px 6px;font-size:12px;color:#CCC;background:#F1F1F1;border-radius:5px;}
    		.close_img:hover,.close_img2:hover{text-decoration: underline;}
    	</style>
	</head>
	<body class="mainbody">
<!--前端需要验证，后台也需要验证，防止前端验证失效的情况，两套验证更加保险-->
<!--导航栏-->
<div class="location">
    <a href="{{U('Goods/index')}}" class="back"><i></i><span>返回列表页</span></a>
    <a href="{{U('Index/index')}}" class="home" target="_blank"><i></i><span>首页</span></a>
    <i class="arrow"></i>
    <a href="{{U('Goods/add')}}"><span>商品管理</span></a>
    <i class="arrow"></i>
    <span>编辑商品</span>
</div>
<div class="line10"></div>
<!--/导航栏-->
		
<!--内容-->
<div id="floatHead" class="content-tab-wrap">
    <div class="content-tab">
    	<div class="content-tab-ul-wrap">
      		<div class="tab-title"><span>编辑商品</span><i></i></div>
      		<ul>
        	<li><a class="selected" href="javascript:;">编辑商品</a></li>   
      		</ul>
    	</div>
    </div>
</div>
<!--上传缩略图 需要enctype="multipart/form-data"和name-->
<form action="" method="post" enctype="multipart/form-data">
<div class="tab-content" style="display: block;">
	<input type="hidden" name="type_tid" value="2"  />	
	<input type="hidden" name="adminuser_aid" value="1"  />		
    <dl id="max">		
	    <dt>所属分类</dt>
	    <dd>
	 		<select name="category_cid"  style="border:1px solid #eee;" >
				<option value="">请选择</option>
					{{foreach from="$cateData" value="$v"}}
						
						<option value="{{$v['cid']}}" type_tid="{{$v['type_tid']}}"  <?php if($goodsOldData[0]['category_cid'] == $v['cid']): ?> selected <?php endif ?> >{{$v['_name']}}</option>				
							
					{{endforeach}}
			</select>
	    </dd>
    </dl>
    <dl>
	    <dt>所属品牌</dt>
	    <dd>
	 		<select name="brand_bid"  style="border:1px solid #eee;" >
				<option value="">请选择</option>
					{{foreach from="$brandData" value="$v"}}
						<option value="{{$v['bid']}}" <?php if($goodsOldData[0]['brand_bid'] == $v['bid']): ?> selected <?php endif ?> >{{$v['bname']}}</option>
					{{endforeach}}
			</select>
	    </dd>
    </dl>  		
	<dl>
	    <dt>商品名称</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="gname" value="{{ $goodsOldData[0]['gname']}}">
	      <span class="Validform_checktip">*商品名称 最多200个字符</span>
	    </dd>
    </dl>
    <dl>
	    <dt>单位</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="unit" value="件" value="{{ $goodsOldData[0]['unit']}}">
	      <span class="Validform_checktip">*商品单位 最多150个字符</span>
	    </dd>
    </dl>
    <dl>
	    <dt>市场价</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="marketprice" value="{{ $goodsOldData[0]['marketprice']}}">
	      <span class="Validform_checktip">*市场价</span>
	    </dd>
    </dl>
    <dl>
	    <dt>商城价</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="shopprice" value="{{ $goodsOldData[0]['shopprice']}}">
	      <span class="Validform_checktip">*商城价</span>
	    </dd>
    </dl>
    <dl>
	    <dt>总库存</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="stock" value="{{ $goodsOldData[0]['stock']}}">
	      <span class="Validform_checktip">*总库存</span>
	    </dd>
    </dl>
    <dl id="mark">
	    <dt>点击次数</dt>
	    <dd>
	    	<input class="input normal" type="text" placeholder="" required="" name="click" value="{{ $goodsOldData[0]['click']}}">
	      <span class="Validform_checktip">*点击次数</span>
	    </dd>
    </dl>	
       
     <!--异步删除列表图-->
  	<script type="text/javascript">
			$(function(){
				if($('#Listmark').attr('src') == ''){
					//不需要用到iframe
					//alert('没有列表图，显示上传插件');
					$('#Listmark').hide();
					$('#uploadB1').show();
				}
				//点击关闭图片按钮
				$('.close_img').click(function(){				
					var listPic = $('#listPic').attr('value');
					var gid = $('#gid').attr('value');
					//发送异步
    				$.ajax({
    					type:"post",
    					url:"{{U('Goods/delListPic')}}",
    					data:{pic:listPic,gid:gid},
    					dataType:'json',
    					success:function(){//请求之后，响应成功执行					
    					}
    				});
    				$('#listPicBox').remove();
					$('#uploadB1').show();
				});			
			});
	</script>  
	<!--异步删除列表图_ok-->
    <dl>
    	<dt>列表图</dt>
	    <dd id="upload_box">
	    	<input type="hidden" value="{{$goodsOldData[0]['gid']}}" id="gid" />
	    	<!--判断有列表图-->
	    	<div id="listPicBox">
	    		{{if value="$goodsOldData[0]['list_pic']"}}
	    		     <!--显示列表图-->
	    		     <img src="{{$goodsOldData[0]['list_pic']}}" width="100" height="50"/>
					 <a href="javascript:;" class="close_img">X</a>
					 <input type="hidden" name="list_pic" value="{{$goodsOldData[0]['list_pic']}}" id="listPic"/>
	    		{{else}}
	    			<!--显示头像-->
	    		     <img src="{{$goodsOldData[0]['list_pic']}}" width="100" height="50" id="Listmark" alt="无图"/>
	    		{{endif}}
    		</div>
	       <!-- 上传 -->
			<div lab="uploadFile" id="uploadB1" style="display:none;">
				<input id="f1" type="file" multiple="true" name="list_pic">
					<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
					<!-- 上传代码 开始 -->
					<script type="text/javascript">
						$(function() {//alert(1);
						$('#f1').uploadify({
						    'formData'     : {//POST数据
						       '<?php echo session_name();?>' : '<?php echo session_id();?>',
						    },
						    'fileTypeDesc' : '上传文件',//上传描述
						    'fileTypeExts' : '*.jpg;*.png',
						    'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
						   'uploader' : '{{U('upload_list')}}',
						     'buttonText':'选择文件',
						    'fileSizeLimit' : '2000KB',
						    'uploadLimit' : 1,//上传文件数
						    'width':65,
						    'height':25,
						    'successTimeout':10,//等待服务器响应时间
						    'removeTimeout' : 0.2,//成功显示时间
						    'onUploadSuccess' : function(file, data, response) {
							//转为json
						   data=$.parseJSON(data);
						    //获得图片地址
						    var imageUrl = data.url;
						    var li="<li path='"+data.path+"' url='"+data.url+"'><img width='100' height='50' src='"+imageUrl+"'/><input type='hidden' name='list_pic' value='"+data.path+"'/></li>";
						    $("#uploadList1 ul").prepend(li);
						 }
						});
						});
					</script>
					<!-- 上传代码  结束-->
					<div id="uploadList1">
						<ul>
						
						</ul>
					</div>
				</div>	
		<!----上传_ok----->
	    </dd>						
  	</dl>
  	
  	
  	<!--<dl>
    	<dt>商品属性</dt>
	    <dd  style="width:600px;">	
	        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="attr">
	        </table>		  
	    </dd>
    </dl>
       
    <dl>
    	<dt>商品规格</dt>
	    <dd  style="width:600px;">
	        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="spec">
	        </table>
	    </dd>
    </dl>-->
     
     
     
     
     <dl>
    	<dt>商品属性</dt>
	    <dd  style="width:600px;">	
	        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="attr">
	        	{{foreach from="$dataattr" value="$v"}}
	        	<tr class="info">
					<td class="w160" align="center">{{$v['taname']}}</td>
					<td>
						<select name="attr[{{$v['taid']}}]">
							<option value="">请选择</option>
							{{foreach from="$v['tavalue']" value="$val"}}
						    <option value="{{$val}}" <?php if($val==$v['gavalue']): ?>selected <?php endif ?> >{{$val}}</option>
						    {{endforeach}}
						</select>
					</td>
				</tr>
				{{endforeach}}
	        </table>		  
	    </dd>
    </dl>
    <dl>
    	<dt>商品规格</dt>
	    <dd  style="width:600px;">
	        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable" id="spec">
	        	{{if value="$dataspec"}}
	        	{{foreach from="$dataspec" value="$v"}}	
	        	<tr class="info">
					<td class="w160" align="center">{{$v['taname']}}</td>
					<td>
						<select name="spec[{{$v['taid']}}][value][]">
							<option value="">请选择</option>	
							{{foreach from="$v['tavalue']" value="$val"}}	
								<option value="{{$val}}" <?php if($val==$v['gavalue']): ?>selected <?php endif ?> >{{$val}}</option>	
							{{endforeach}}	
						</select>
					</td>
					<td>附加价格：<input type="text" name="spec[{{$v['taid']}}][add_price][]" value="{{$v['add_price']}}"/></td>
					<td><span class="btn-gray add-spec">增加规格</span></td>
				</tr>
				{{endforeach}}
				{{endif}}
	        </table>
	    </dd>
    </dl>
    
     
     
	<!--<dl>
		<h6>商品属性</h6>	
		{{foreach from="$dataattr" value="$v"}}				
			{{$v['taname']}}<br />
				<select class="form-control" name="attr[{{$v['taid']}}]">
					<option value="">请选择</option>
					{{foreach from="$v['tavalue']" value="$val"}}	
					<option value="{{$val}}" <?php if($val==$v['gavalue']): ?>selected <?php endif ?>>{{$val}}</option>	
					{{endforeach}}
				</select>
		{{endforeach}}										
	</dl>					
	<dl>
		<dt>商品规格</dt>		
		{{foreach from="$dataspec" value="$v"}}				
			{{$v['taname']}}</br>
				<select class="" name="spec[{{$v['taid']}}][value][]">
					<option value="">请选择</option>
					{{foreach from="$v['tavalue']" value="$val"}}	
						<option value="{{$val}}" <?php if($val==$v['gavalue']): ?>selected <?php endif ?> >{{$val}}</option>	
					{{endforeach}}
				</select>
				<label >附加价格</label><input name="spec[{{$v['taid']}}][add_price][]" id="" value="{{$v['add_price']}}" type="text"><a class="addattr" href="javascript:;">添加规格</a>&nbsp;&nbsp;<a class="removeattr" href="javascript:;">删除规格</a><br/>
		{{endforeach}}				
	</dl>-->
  						
  	<script type="text/javascript">
			$(function(){		
				//点击关闭图片按钮
				$('.close_img2').click(function(){
					//获得ID
					var gid = $('#gid').attr('value');			
					//发送异步
    				$.ajax({
    					type:"post",
    					url:"{{U('Goods/delDetailPic')}}",
    					data:{gid:gid},
    					dataType:'json',
    					success:function(){//请求之后，响应成功执行						
    					}
    				});
    				$('#mostBox').remove();
				})
			})
	</script>
  	<dl>
    	<dt>详细页图册</dt>
	    <dd id="upload_box2">
	    	<!--如果有头像--> 
	    	<div id="mostBox">	  		    		
    			{{foreach from="$detailOldData['detail_pic']" key="$k" value="$v" }}
    		     <!--显示头像--> 		    
	    		     <p id="dPicBox" style="display:inline-block;">		     
		    		     <img src="{{$v}}" width="100" height="50" alt="无图"/>    		     
						 <input type="hidden" name="detail_picOld[]" value="{{$v}}" id="detailPic"/>
					</p>	
				 {{endforeach}} 			 
				 <a href="javascript:;" class="close_img2" pic="{{$v}}">X</a>
			</div> 
	       <!-- 上传-->
	        <div lab="uploadFile">
				 <input id="f2" type="file" multiple="true" name="detail_pic">
				<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
					<script type="text/javascript">
						$(function() {
						$('#f2').uploadify({
						   'formData'     : {//POST数据
						        '<?php echo session_name();?>' : '<?php echo session_id();?>',
						     },
						    'fileTypeDesc' : '上传文件',//上传描述
						   'fileTypeExts' : '*.jpg;*.png',
						    'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
						    'uploader' : '{{U('upload_most')}}',
						    'buttonText':'选择文件',
						    'fileSizeLimit' : '2000KB',
						     'uploadLimit' : 20,//上传文件数
						    'width':65,
						     'height':25,
						     'successTimeout':10,//等待服务器响应时间
						     'removeTimeout' : 0.2,//成功显示时间
						     'onUploadSuccess' : function(file, data, response) {
							//转为json
						     data=$.parseJSON(data);
						      //获得图片地址
						      var imageUrl = data.url;
						     var li="<li path='"+data.path+"' url='"+data.url+"'><img width='100' height='50' src='"+imageUrl+"'/><input type='hidden' name='detail_pic[]' value='"+data.path+"'/></li>";
						          $("#uploadList2 ul").prepend(li);
						      }
						 });
						});
					</script>
				<style type="text/css">
			    	#uploadList2 ul li{width:100px;height:50px;display:inline-block;float:left;margin-right:5px;}
			    </style>
				<div id="uploadList2">
					<ul>
					
					</ul>
				</div>
			</div>	
			<!--上传_ok-->				           
	    </dd>
  	</dl>
  	
	<dl>
	    <dt>商品详细</dt>
	    <dd>
	        <!--调用百度编辑器 商品详细表 name="detail_desc"-->  
			<script id="detail_desc" name="detail_desc" type="text/plain" style="width:100%;height:260px;">{{ $detailOldData['detail_desc']}}</script>
			<script>
			var ue = UE.getEditor('detail_desc');
			</script>
	    </dd>
    </dl>
    
    <dl>
	    <dt>售后服务</dt>
	    <dd>
	        <!--调用百度编辑器    商品详细表 name="detail_service"-->
			<script id="detail_service" name="detail_service" type="text/plain" style="width:100%;height:260px;">{{ $detailOldData['detail_service']}}</script>
			<script>
			var ue = UE.getEditor('detail_service');
			</script>
	    </dd>
    </dl>
    
  	
  		
</div>
<!--/内容-->
		
<!--工具栏-->
<div class="page-footer">
  <div class="btn-wrap" style="position: static;">
    <input type="submit" name="btnSubmit" value="提交保存" id="btnSubmit" class="btn">
    <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);">
  </div>
</div>
<!--/工具栏-->
</form>	

	</body>
</html>